package common;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

public class InitAndCloseWith2Driver {
    public static WebDriver webDriver;
    public static WebDriver webDriver2;

    @BeforeAll
    public static void setUp() {
        webDriver = new ChromeDriver();
        webDriver2 = new ChromeDriver();
    }

    @AfterAll
    public static void close() {
        webDriver.quit();
        webDriver2.quit();
    }

    public void loginWith2() {
        String user1 = "zhangsan";
        String password1 = "123456";

        String user2 = "lisi";
        String password2 = "123456";

        // zhangsan 登录
        webDriver.get("http://8.130.172.144:8081/login.html");
        // 等待页面加载完成
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        // 输入账号
        webDriver.findElement(By.cssSelector("#username")).sendKeys(user1);
        // 输入密码并按下回车
        webDriver.findElement(By.cssSelector("#password")).sendKeys(password1, Keys.ENTER);

        // lisi 登录
        webDriver2.get("http://8.130.172.144:8081/login.html");
        // 等待页面加载完成
        webDriver2.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        // 输入账号
        webDriver2.findElement(By.cssSelector("#username")).sendKeys(user2);
        // 输入密码并按下回车
        webDriver2.findElement(By.cssSelector("#password")).sendKeys(password2, Keys.ENTER);
    }
}
